package com.blackhorse.service;
/*
Product product = restTemplate.getForObject("http://service-product/product/" + pid, Product.class);
 */

import com.blackhorse.domain.Product;
import com.blackhorse.service.fallback.ProductServiceFallback;
import com.blackhorse.service.fallback.ProductServiceFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * FeignClient用于指定这是一个Feign远程调用接口，服务提供者服务名为service-product
 * feign可生成此接口的代理对象，无需编写实现类
 * value: 指定调用注册中心中的服务名
 *
 * 注意：测试seata时去掉fallback和fallbackFactory
 */
@FeignClient(
    value = "service-product"
//    fallback = ProductServiceFallback.class, //指定容错类实现类
//    fallbackFactory = ProductServiceFallbackFactory.class //指定容错类工厂实现类（fallback和fallbackFactory只用一个）
)
public interface ProductService {

    /**
     * RequestMapping 指定请求路径，写法与spring mvc完全一致
     * 最终feign调用的url为：FeignClient.value+RequestMapping.value
     */
    @RequestMapping("/product/{pid}")
    Product findByPid(@PathVariable Integer pid);

    /**
     * 扣减商品库存
     *
     * @param pid    商品ID
     * @param number 扣减数量
     */
    @RequestMapping("/product/reduceInventory")
    void reduceInventory(@RequestParam("pid") Integer pid,
                         @RequestParam("number") Integer number);
}
